﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using INTREPWEB.Models;
using System.Threading;

namespace INTREPWEB.Controllers
{
    public class ParcialController : Controller
    {
        private INTREPDB db = new INTREPDB();

        public ActionResult Armador(int? id)
        {
            if (id.HasValue)
            {
                var navio = db.Navios.Find(id);

                ViewBag.Armadores = new SelectList(db.Armadores, "Id", "Nome", navio.ArmadorId);
            }
            else
            {
                ViewBag.Armadores = new SelectList(db.Armadores, "Id", "Nome");
            }

            return View();
        }

        public ActionResult Navio(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                ViewBag.Navios = new SelectList(db.Navios, "Id", "Nome");
            }
            else
            {
                var embarque = db.Embarques.Find(id);

                ViewBag.Navios = new SelectList(db.Navios, "Id", "Nome", embarque.Navio.Id);
            }

            return View();
        }

        public ViewResult Item(string id)
        {
            // TODO remover atraso
            Thread.Sleep(2000);
            return View(db.EmbarqueItems.Where(x => x.Embarque.Id == id).ToList());
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}
